VXLANs_CONFIG={
    100:{"VNI":100,"ROUTING_ALGORITHM":"Hop"},
    200:{"VNI":200,"ROUTING_ALGORITHM":"Hop"}
}
VTEPs_CONFIG={
    1:{"DPID":1,"VXLAN_PORT_FOR_FORWARD":{100:5,200:6},"LOCAL_PORT_FOR_TAG":{3:100,4:200}},
    2:{"DPID":2,"VXLAN_PORT_FOR_FORWARD":{},"LOCAL_PORT_FOR_TAG":{}},
    3:{"DPID":3,"VXLAN_PORT_FOR_FORWARD":{100:5,200:6},"LOCAL_PORT_FOR_TAG":{3:200,4:100}}
}
# TODO 两个端口都可以转发如何处理

class VXLAN:
    def __init__(self,vxlan_config):
        self.Vni=vxlan_config["VNI"]
        self.Routing_Algorithm=vxlan_config["ROUTING_ALGORITHM"]
        
class VTEP:
    def __init__(self,vtep_config):
        self.Dpid=vtep_config["DPID"] 
        
        #初始化数据包应当从哪个端口转发
        self.Vxlan_Port_For_Forward={}
        for vni,vxlan_port in vtep_config["VXLAN_PORT_FOR_FORWARD"].items():
            self.Vxlan_Port_For_Forward[vni]=vxlan_port
            
        #初始化本地数据包应当被打上哪个vni标签
        self.Local_Port_For_Tag={}
        for local_port,vni in vtep_config["LOCAL_PORT_FOR_TAG"].items():
            self.Local_Port_For_Tag[local_port]=vni
        
class FORWARDING_TABLE:
    def __init__(self):
        self.Rules={}
        
class MULTI_TENANT_NETWORK:
    
    def __init__(self,vxlans_config,vteps_config):
        
        #实例化各vxlan
        self.Vxlans={}
        for vni,vxlan_config in vxlans_config.items():
            self.Vxlans[vni]=VXLAN(vxlan_config)
        
        #实例化各vtep
        self.Vteps={}
        for dpid,vtep_config in vteps_config.items():
            self.Vteps[dpid]=VTEP(vtep_config)
        
        #实例化转发表
        self.Forwarding_Table=FORWARDING_TABLE()
        
        
if __name__ == '__main__':
    multi_tenant_network=MULTI_TENANT_NETWORK(VXLANs_CONFIG,VTEPs_CONFIG)
    dpid=1
    # for local_port,vni in multi_tenant_network.Vteps[dpid].Local_Port_For_Tag.items():
    #         print(local_port)
    # rule={("00:00:00:00:01:01",100):13}
    # multi_tenant_network.Forwarding_Table.Rules[dpid]=rule
    # # print(multi_tenant_network.Forwarding_Table.Rules[dpid][("00:00:00:00:01:01",100)])
    # vxlan_ports=multi_tenant_network.Vteps[dpid].Vxlan_Port_For_Forward[vni][:]
    # local_ports=multi_tenant_network.Vteps[dpid].Local_Port_For_Tag.keys()
    # print(vxlan_ports)
    # print(list(local_ports))
    for vni,vxlan_port in multi_tenant_network.Vteps[dpid].Vxlan_Port_For_Forward.items():
        print(vni,vxlan_port)
        